import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete, ParseUUIDPipe,
} from '@nestjs/common';
import { HouseworkService } from './housework.service';
import { CreateHouseworkDto } from './dto/create-housework.dto';
import { UpdateHouseworkDto } from './dto/update-housework.dto';
import {ApiOkResponse, ApiOperation, ApiTags} from '@nestjs/swagger';
import {houseworkEntity} from "./entities/housework.entity";
@ApiTags('housework')
@Controller('housework')
export class HouseworkController {
  constructor(private readonly houseworkService: HouseworkService) {}

  @Post()
   async create(@Body() createHouseworkDto: CreateHouseworkDto) {
    return new houseworkEntity(await this.houseworkService.create(createHouseworkDto));
  }

  @Get('user/:id')
  @ApiOkResponse({ type: houseworkEntity, isArray: true })
  @ApiOperation({summary: '根据用户id寻找订单'})
  async findAllById(@Param('id',ParseUUIDPipe) id:string) {
    const houseWorks =await this.houseworkService.findAllById(id);
    return houseWorks.map((houseWork) => new houseworkEntity(houseWork));
  }
  @Get()
  @ApiOkResponse({ type: houseworkEntity, isArray: true })
  @ApiOperation({summary: '获得全部订单'})
  async findAll() {
    const houseWorks =await this.houseworkService.findAll();
    return houseWorks.map((houseWork) => new houseworkEntity(houseWork));
  }
  @Get(':id')
  async findOne(@Param('id',ParseUUIDPipe) id: string) {
    return new houseworkEntity(await this.houseworkService.findOne(id));
  }

  @Patch(':id')
  async update(
    @Param('id',ParseUUIDPipe) id: string,
  ) {
    return new houseworkEntity(
        await this.houseworkService.update(id)
    );
  }

  @Delete(':id')
  async remove(@Param('id',ParseUUIDPipe) id: string) {
    return new houseworkEntity(await this.houseworkService.remove(id));
  }
}
